package com.hs.ding.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hs.ding.pojo.Dispatch;
import com.hs.ding.service.IDispatchService;
import com.hs.dto.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ding
 * @since 2022-06-20
 */
@CrossOrigin
@RestController
@RequestMapping("/dispatch")
public class DispatchController {

    @Autowired
    private IDispatchService iDispatchService;

    @GetMapping("page")
    public ResultBean findAllByPage(Integer currentPage, Integer pageSize,String dOrderId){

        ResultBean allDispatch = iDispatchService.findAllDispatch(currentPage, pageSize,dOrderId);

        return allDispatch;
    }

    @PostMapping("/manage")
    public ResultBean changeStatus(@RequestBody Dispatch dispatch){

        System.out.println("dispatch = " + dispatch);
        String id = dispatch.getdOrderId();
        UpdateWrapper<Dispatch> uw = new UpdateWrapper<>();
        uw.set("d_status",1);
        uw.eq("d_order_id",id);
        boolean b = iDispatchService.update(uw);

        return b ? ResultBean.OK():ResultBean.ERROR();
    }


    /**
     * 查找 已处理 的 派车订单
     * @return
     */
    public List<Dispatch> searchDispatchs(){

        List<Dispatch> dispatches  = iDispatchService.findDealDispatch();

        return dispatches;
    }

}
